import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

export const constantRoutes = [
    {
        path: '/',
        redirect: '/baseInfo'
        // component: ()=>import('../views/baseInfo/index.vue'),
    },
    {
        path: '/baseInfo',
        component: () => import('../views/baseInfo/index.vue'),
    },
    {
        path: '/diskInfo',
        component: () => import('../views/diskInfo/index.vue'),
    },
    {
        path: '/taxClass',
        component: () => import('../views/taxClass/index.vue'),
    },
    {
        path: '/availableTax',
        component: () => import('../views/availableTax/index.vue'),
    },
    { //
        path: '/creditLimit',
        component: () => import('../views/creditLimit/index.vue'),
    },
    { //
        path: '/preShareCode',
        component: () => import('../views/preShareCode/index.vue'),
    },
    { //
        path: '/invoiceTemplate',
        component: () => import('../views/invoiceTemplate/index.vue'),
    },
    { //
        path: '/myAgent',
        component: () => import('../views/myAgent/index.vue'),
    },
    { //
        path: '/handleDetail',
        // component: ()=>import('../views/home/handleDetail/newIndex.vue'),
        component: () => import('../views/home/handleDetail/index.vue'),
    },
    { //
        path: '/handInvoiceAdd',
        component: () => import('../views/handInvoiceAdd/index.vue'),
    },
    { //
        path: '/invoicedInfo',
        component: () => import('../views/invoicedInfo/index.vue'),
    },


    {
        path: '/home',
        component: () => import('../views/home/index.vue'),
    },
    {
        path: '/dev',
        component: () => import('../views/dev/index.vue'),
    },
    {
        path: '/custom',
        component: () => import('../views/custom/index.vue'),
    },


// part2
    {  // 4.1企业商品及服务信息管理
        path: '/serviceInformationManage',
        component: () => import('../views/serviceInformationManage/index.vue'),
    },
    {  // 4.2用户基本信息
        path: '/userBasicInformation',
        component: () => import('../views/userBasicInformation/index.vue'),
    },
    {  // 4.3
        path: '/flowInvoice',
        component: () => import('../views/flowInvoice/index.vue'),
    },
    {  // 4.4
        path: '/manualNegativeInvoice',
        component: () => import('../views/manualNegativeInvoice/index.vue'),
    },
    {  // 4.6
        path: '/invoiceSummryConfirm',
        component: () => import('../views/invoiceSummryConfirm/index.vue'),
    },

    {  // 4.7红票确认单 申请
        path: '/redConfirmApply',
        component: () => import('../views/redConfirmApply/index.vue'),
    },
    {   // 4.8红票确认单 申请
        path: '/redConfirmForm',
        component: () => import('../views/redConfirmForm/index.vue'),
    },

    // part3
    {   // 发票归集
        path: '/invoiceCollection',
        component: () => import('../views/invoiceCollection/index.vue'),
    },
    {   // 发票查验
        path: '/invoiceVericication',
        component: () => import('../views/invoiceVericication/index.vue'),
    },

    {
        path: '/404',
        component: () => import('@/views/404'),
        hidden: true
    },

    {path: '*', redirect: '/404', hidden: true}
]

const createRouter = () => new Router({
    scrollBehavior: () => ({y: 0}),
    routes: constantRoutes
})

const router = createRouter()
router.beforeEach((to, form, next) => {
    try {
        let ww = to.fullPath.split('?token=');
        let c = ww[1];
        if (c) {
            sessionStorage.setItem('tokenIframe', c)

        }
    } catch (error) {

    }
    next()
})

export function resetRouter() {
    const newRouter = createRouter()
    router.matcher = newRouter.matcher // reset router
}

export default router
